package cvo.chess.tests.pieces;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.List;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import cvo.chess.client.entities.IGameFacade;
import cvo.chess.client.entities.armies.pieces.Bishop;
import cvo.chess.client.entities.armies.pieces.Pawn;
import cvo.chess.client.entities.chessboard.ChessboardCoordinate;
import cvo.chess.client.entities.chessboard.IChessboardCoordinate;
import cvo.chess.client.entities.chessboard.ITile;
import cvo.chess.client.entities.game.Army;
import cvo.chess.client.entities.game.Chessboard;
import cvo.chess.client.entities.game.IPiece;

public class BishopTestPossibleMoves {
	private IGameFacade gf;
	private ITile tile;
	private Chessboard board;
	private IChessboardCoordinate chessco,chesscoBlack,chesscoWhite;
	private Army army;
	
	@Before
	public void setUp(){
		gf = mock(IGameFacade.class);
		tile = mock(ITile.class);
		when(tile.getPosition()).thenReturn("A1");
		when(gf.getTileAt("A1")).thenReturn(tile);
		
		army = mock(Army.class);
		when(army.getColor()).thenReturn("WHITE");
		
		
		board = mock(Chessboard.class);
		when(board.getHeight()).thenReturn(8);
		when(board.getWidth()).thenReturn(8);
		
		chessco = mock(IChessboardCoordinate.class);
		
	}
	
	@Test
	public void testMockito(){
		ITile t = gf.getTileAt("A1");
		Assert.assertEquals("Postion must be A1", "A1", t.getPosition());
	}
	
	@Test 
	public void testWhenBishopOnC4() throws Exception{
		IPiece bishop = new Bishop(gf, army);	
		
		chessco.setA1Notation("C4");
		when(chessco.getRow()).thenReturn(2);
		when(chessco.getCol()).thenReturn(4);
		when(chessco.getA1Notation()).thenReturn("C4");
		when(gf.getPositionOfPiece(bishop)).thenReturn(chessco);	
		
		gf.setPieceAtPosition(bishop, chessco);
		
		Assert.assertNotNull("List of possible moves may not be null", bishop.getPossibleMoves());
		
		Assert.assertFalse("List must contain more possible moves", bishop.getPossibleMoves().isEmpty());
		
		List<ChessboardCoordinate> list = bishop.getPossibleMoves();
		
		Assert.assertTrue("Does contain B3", list.contains(new ChessboardCoordinate(board, "B3")));
		Assert.assertTrue("Does contain A6", list.contains(new ChessboardCoordinate(board, "A6")));
		Assert.assertTrue("Does contain F8", list.contains(new ChessboardCoordinate(board, "F8")));
		Assert.assertFalse("Does not contain C5", list.contains(new ChessboardCoordinate(board, "C5")));
		Assert.assertFalse("Does not contain E3", list.contains(new ChessboardCoordinate(board, "E3")));
		
		Assert.assertFalse("May not be included int possMoves", list.contains(new ChessboardCoordinate(board,"D1")));
		Assert.assertFalse("May not be included int possMoves", list.contains(new ChessboardCoordinate(board,"D4")));
	}
	
	@Test 
	public void testWhenBishopOnD1() throws Exception{
		IPiece bishop = new Bishop(gf, army);	
		
		chessco.setA1Notation("D1");
		when(chessco.getRow()).thenReturn(3);
		when(chessco.getCol()).thenReturn(7);
		when(chessco.getA1Notation()).thenReturn("D1");
		when(gf.getPositionOfPiece(bishop)).thenReturn(chessco);	
		
		gf.setPieceAtPosition(bishop, chessco);
		
		Assert.assertNotNull("List of possible moves may not be null", bishop.getPossibleMoves());
		
		Assert.assertFalse("List must contain more possible moves", bishop.getPossibleMoves().isEmpty());
		
		List<ChessboardCoordinate> list = bishop.getPossibleMoves();
		
		Assert.assertTrue("Does contain A4", list.contains(new ChessboardCoordinate(board, "A4")));
		Assert.assertFalse("Does not contain C1", list.contains(new ChessboardCoordinate(board, "C1")));
		
		Assert.assertFalse("May not be included int possMoves", list.contains(new ChessboardCoordinate(board,"E1")));
		Assert.assertFalse("May not be included int possMoves", list.contains(new ChessboardCoordinate(board,"F4")));
	}
	
//	@Test
//	public void testWhenBishopOnC4WithBlackAndWhitePawns()throws Exception{
//		IPiece bishop = new Bishop(gf, army);
//		IPiece pawn1black = new Pawn(gf, army);
//		IPiece pawn1white = new Pawn(gf, army);
//		
//		chessco.setA1Notation("C4");
//		when(chessco.getRow()).thenReturn(2);
//		when(chessco.getCol()).thenReturn(4);
//		when(gf.getPositionOfPiece(bishop)).thenReturn(chessco);	
//		gf.setPieceAtPosition(bishop, chessco);
//		
//		chesscoWhite.setA1Notation("D3");
//		when(chesscoWhite.getRow()).thenReturn(3);
//		when(chesscoWhite.getCol()).thenReturn(5);
//		when(gf.getPositionOfPiece(pawn1white)).thenReturn(chesscoWhite);	
//		gf.setPieceAtPosition(pawn1white, chesscoWhite);
//		
//		chesscoBlack.setA1Notation("D5");
//		when(chesscoBlack.getRow()).thenReturn(3);
//		when(chesscoBlack.getCol()).thenReturn(3);
//		when(gf.getPositionOfPiece(pawn1black)).thenReturn(chesscoBlack);	
//		gf.setPieceAtPosition(pawn1black, chesscoBlack);
//		
//		Assert.assertNotNull("List of possible moves may not be null", bishop.getPossibleMoves());
//		
//		Assert.assertFalse("List must contain more possible moves", bishop.getPossibleMoves().isEmpty());
//		
//		List<ChessboardCoordinate> list = bishop.getPossibleMoves();
//		
//		Assert.assertTrue("Does contain D5", list.contains(new ChessboardCoordinate(board, "D5")));
//		Assert.assertFalse("Does not contain D3", list.contains(new ChessboardCoordinate(board, "D3")));
//		Assert.assertFalse("Does not contain E6", list.contains(new ChessboardCoordinate(board, "E6")));
//		Assert.assertFalse("Does not contain E2", list.contains(new ChessboardCoordinate(board, "E2")));
//
//	}
	
	
}
